#include <stdio.h>

void aaa()
{
	int *p;
}

void bbb()
{
	int a = 4;
	int *p = &a;
}

void ccc()
{
	int a[10];
	int *p;

	p = a;

	p = &a[0];
}

void ddd()
{
	int a[10];
	int *p;

	a[0] = 1;
	a[1] = 2;
	a[2] = 3;

	p = a;

	p = &a[0];
}

int eee()
{
	//				0   1   2   3  4   5   6
	int data[10] = {10, 15, 20, 25, 30, 35, 40};
	int *src;
	int *des;

	
	src = data;	// 10
	
	src = src + 3;
	printf("%d\n", *src);			// 25
	printf("%d\n", *(src + 3));	// 40 没有移位
	printf("%d\n", src[3]);		// 40 没有移位

	src = data;
	printf("%d\n", *(src + 3));	// 25 没有移位
	printf("%d\n", src[3]);		// 25 没有移位
	
	src++;	// 移到下一位
	printf("%d\n", *src);		// 15

	src = data;
	des = src;
	printf("%d : des = %d\n", __LINE__, *des);	// 10
	des++;
	printf("%d : des = %d\n", __LINE__, *des);	// 15
	printf("%d : des = %d\n", __LINE__, *++des);	// 20
	printf("%d : src = %d\n", __LINE__, *src);	// 10 src被des操作,但src本身没有移动,仍指向data首地址.
}

int fff(void)
{
	int urn[5] = {100, 200, 300, 400, 500};
	int *ptr1, *ptr2, *ptr3;

	ptr1 = urn;
	ptr2 = &urn[2];

	printf("pointer value, dereferenced pointer, pointer address:\n");
	printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n", ptr1, *ptr1, &ptr1);	// 100

	// pointer addition   + 
	ptr3 = ptr1 + 4;
		printf("\t==xiaozi ==== %d\n", *ptr3);	// 500
		
	printf("\n adding an int to a pointer:\n");
	printf("ptr1 + 4 = %p, *(ptr4 + 3) = %d\n", 
				ptr1 + 4, *(ptr1 + 3));	// 400
				

	ptr1++;			// increase by degrees point    dizeng point
		printf("\t==xiaozi ==== %d\n", *ptr1);	// 200
		
	printf("\n values after ptr1++\n");
	printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n", 
				ptr1, *ptr1, &ptr1);	// 200

	ptr2--;			// descending		diqian point
	printf("\n values after --ptr2\n");
	printf("ptr2 = %p, *ptr2 = %d, &ptr2 = %p\n", 
				ptr2, *ptr2, &ptr2);	// 200

	--ptr1;			// huifu wei chu shi zhi
	++ptr2;			// huifu wei chu shi zhi
		printf("\t==xiaozi ==== %d\n", *ptr1);	// 100
		printf("\t==xiaozi ==== %d\n", *ptr2);	// 300
	printf("\n pointers reset to original values:\n");
	printf("ptr1 = %p, ptr2 = %p\n", 
					ptr1, ptr2);	// 300

	// yige point qianqu ling yige point
	printf("\n subtracting one pointer from another:\n");
	printf("ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %d\n", 
						ptr2, ptr1, ptr2 - ptr1); // 2


	// yige point qianqu yige zhengshu
	printf("\n subtracting an int from a pointer:\n");
	printf("ptr3 = %p, ptr3 - 2 = %p\n", 
					ptr3, ptr3 - 2);

}

void point()
{
	int data[2] = {100, 200};
	int moredata[2] = {300, 400};

	int *p1, *p2, *p3;

	p1 = p2 = data;
	p3 = moredata;
	
	printf("   *p1 = %d, *p2 = %d, *p3 = %d\n", 
			*p1, *p2, *p3);	// 100 100 300

	printf("   *p1++ = %d, *++p2 = %d, (*p3)++ = %d\n", 
			*p1++, *++p2, (*p3)++);	// 100 200 300

	printf("   *p1 = %d, *p2 = %d, *p3 = %d\n", 
			*p1, *p2, *p3);	// 200 200 301
}

void modify_array()
{
	int data[2] = {100, 200};
	int *p;
	int i;
	
	p = data;
	*p = 102;
	for (i = 0; i < 2; i++)
		printf("data[%d] = %d\n", i, data[i]);	// 102  200
	
}

int ggg(void)
{
	int array0[10] = {10, 15, 20, 25, 30,40};
	int array1[10] = {10, 15, 20, 25, 30,40};
	int array2[10] = {10, 15, 20, 25, 30,40};
	int array3[10] = {10, 15, 20, 25, 30,40};
	int array4[10] = {10, 15, 20, 25, 30,40};
	int array5[10] = {10, 15, 20, 25, 30,40};
	int array6[10] = {10, 15, 20, 25, 30,40};
	int array7[10] = {10, 15, 20, 25, 30,40};
	int *p;
	
	p = array0;
	printf("*p++ = %d\n", *p++);	// 10
	printf("*p++ = %d\n", *p++);	// 15
	printf("*p++ = %d\n", *p++);	// 20
	
	p = array1;
	printf("\t*++p = %d\n", *++p);	// 15
	printf("\t*++p = %d\n", *++p);	// 20
	printf("\t*++p = %d\n", *++p);	// 25
	
	p = array2;
	printf("(*p)++ = %d\n", (*p)++);	// 10
	printf("(*p)++ = %d\n", (*p)++);	// 11
	printf("(*p)++ = %d\n", (*p)++);	// 12
	
	p = array3;
	printf("\t++*p = %d\n", ++*p);	// 11
	printf("\t++*p = %d\n", ++*p);	// 12
	printf("\t++*p = %d\n", ++*p);	// 13
	
	p = array4;
	printf("++(*p) = %d\n", ++(*p));	// 11
	printf("++(*p) = %d\n", ++(*p));	// 12
	printf("++(*p) = %d\n", ++(*p));	// 13
	
	point();
	modify_array();

	return 0;
}

void x()
{
	int *ptr;
	int torf[2][2] = {12, 14, 16};

	ptr = torf[0];
	printf("*ptr = %d\n", *ptr);		// 12
	printf("*(ptr+2) = %d\n", *(ptr+2));	// 16
}

int y()
{
	int *ptr;
	int fort[2][2] = { {12}, {14, 16} };

	ptr = fort[0];
	printf("*ptr = %d\n", *ptr);		// 12
	printf("*(ptr+2) = %d\n", *(ptr+2));	// 14
}

int w()
{
	int (*ptr)[2];
	int torf[2][2] = {12, 14, 16};

	ptr = torf;
	printf("**ptr = %d\n", **ptr);		// 12
	printf("**(ptr+1) = %d\n", **(ptr+1));	// 16
}

int z()
{
	int (*ptr)[2];
	int forf[2][2] = { { 12 }, 14, 16};

	ptr = forf;
	printf("**ptr = %d\n", **ptr);		// 12
	printf("**(ptr+1) = %d\n", **(ptr+1));	// 14
}


int hhh()
{
	x();
	printf("-------------------------------------\n");
	y();
	printf("-------------------------------------\n");
	w();
	printf("-------------------------------------\n");
	z();
}

void v()
{
	char *p[5];
	
	printf("sizeof(*p[5]) = %d %d %d\n", sizeof(*p[4]), sizeof(p[4]), sizeof(p));	// 1 4 20
}

int array(void)
{
	int zippo[4][2] = { {2,4}, {6, 8}, {1, 3}, {5, 7} };

	printf(" zippo = %p\t, zippo + 1 = %p\n", 	zippo, zippo + 1);
	printf(" zippo[0] = %p\t, zippo[0] + 1 = %p\n", zippo[0], zippo[0] + 1);
	printf(" *zippo = %p\t, *zippo + 1 = %p\n\n", 	*zippo, *zippo + 1);
	
	printf(" zippo[0][0] = %d\n", 	zippo[0][0]);
	printf(" *zippo[0] = %d\n", 	*zippo[0]);
	printf(" **zippo = %d\n", 	**zippo);
	printf(" zippo[2][1] = %d\n", 	zippo[2][1]);
	printf(" *(*(zippo + 2) + 1) = %d\n", 	* ( * (zippo + 2) + 1));

	return 0;

}


int array_point(void)
{
	int zippo[4][2] = { {2,4}, {6, 8}, {1, 3}, {5, 7} };
	int (*pz)[2];

	pz = zippo;

	printf(" pz = %p\t, pz + 1 = %p\n", 		pz, pz + 1);
	printf(" pz[0] = %p\t, pz[0] + 1 = %p\n", 	pz[0], pz[0] + 1);
	printf(" *pz = %p\t, *pz + 1 = %p\n\n", 		*pz, *pz + 1);
	
	printf(" pz[0][0] = %d\n", 			pz[0][0]);	// 2
	printf(" *pz[0] = %d\n", 			*pz[0]);	// 2
	printf(" **pz = %d\n", 				**pz);		// 2
	printf(" pz[2][1] = %d\n",			pz[2][1]);	// 3
	printf(" *(*(pz + 2) + 1) = %d\n", 		* ( * (pz + 2) + 1) );	// 3

	return 0;

}

void evaluate()
{
	int *pt;		// C primer plus  P281
	int (*pa)[3];
	
	int ar1[2][3];
	int ar2[3][2];
	
	int **p2;

	pt = &ar1[0][0];
	pt = ar1[0];
	pt = ar1;	// warning: assignment from incompatible pointer type
	
	pa = ar1;
	pa = ar2;	// warning: assignment from incompatible pointer type
	
	p2 = &pt;
	*p2 = ar1[0];
	*p2 = ar2[0];
	p2 = ar2;	// warning: assignment from incompatible pointer type
}

int tttt()
{
	array();
	array_point();
	
	return 0;
}

typedef void (*pFUNC)();
typedef   int   (*PARA)[5]; 
typedef   PARA   (*func)(int   *); 

#define SIG_ERR (void (*)())-1
#define SIG_DFL (void (*)())0
#define SIG_IGN (void (*)())1

void ( *signal ( int signo, void ( *func ) (int) ) ) (int);

int (*pf)(void);

int f(void)
{
	printf("================= wise\n");
	return 1;
}

void test_pf()
{
	pf = &f;
	pf();
	pf = ****f;
	pf();
	(***************************************************f)();
}

void t(void)
{
	printf("test ******* invoke\n");
}

void point_define()
{
	int *iptr;
	char *cptr;
	int *iiptr;
	int (*ptr)[3];
	int *(*pptr)[4];

	int * (* (*fp1) (int) ) [10];
	(*(void (*)())0)();
	float ( * ( *b()) [] )();
	void * ( *c) ( char, int (*)());
//	void ** (*d) (int &, char **(*)(char *, char **));
//	float ( * (*e[10]) (int &) ) [5];
	int   (*funcun)(int   *p); 
	int   (*fununc)(int   *p,   int   (*f)(int*)); 
	int   (*funnncc[5])(int   *p);
	int   (*(*fuunnc)[5])(int   *p);
	int   (*(*ffuunc)(int   *p))[5];
//	int   fuunc(void)[5];
//	int   fffunc[5](void); 
	int   (*(*funcccc)[5][6])[7][8];
	int   (*(*(*funccc)(int   *)) [5])(int   *); 
	int   (*(*funcc[7][8][9]) (int*)) [5]; 
	int   (*(*func)(int   *p))[5];

}

int iii()
{
	test_pf();
	(***************************test_pf)();
	(***************************t)();
	(*t)();
	(**t)();
	(t)();
	t();

	return 0;
}


int main()
{
	
	return 0;
}


